﻿using System;
using System.Collections.Generic;
using System.Text;

using HyEduOnline.Entities;
using HyEduOnline.Data;

namespace HyEduOnline.Server.Teacher
{
	/// <summary>
	///		此用于处理表对象 'tb_TeaPublicSourceDict' 
	/// </summary>
	/// <remarks>
	/// 	此结构由代码由TMS使用代码生成器书写生成，请不要直接修改.
	///注意:此代码可能和同名的视图生成一个完整对象
	/// </remarks>
	

	
	public partial class TeaPublicSourceDictBaseDAO
	{
		
	#region 表生成代码
		protected int TotalCount = -1;
		
		
		/// <summary>
       
		
		/// <summary>
        /// 取所有的对象,例如TList<???>
        /// </summary>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public  TList<TbTeaPublicSourceDict> GetAll()
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.GetAll();
        }

		/// <summary>
        /// 通过id来取对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public TbTeaPublicSourceDict GetByID(int id)
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.GetById(id);
        }

        /// <summary>
        /// 条件查询分页
        /// </summary>
        /// <param name="whereClause">条件</param>
        /// <param name="startRowIndex">起始值</param>
        /// <param name="maximumRows">每页的最大值</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public  TList<TbTeaPublicSourceDict> GetByPage(string whereClause, int startRowIndex, int maximumRows)
        {

            return DataRepository.Provider.TbTeaPublicSourceDictProvider.GetPaged(whereClause, "ID", (int)startRowIndex / maximumRows, maximumRows, out TotalCount);

        }
		
		 /// <summary>
        ///支持Ext的分页查询,表
        /// </summary>
        /// <param name="whereClause">查询条件</param>
        /// <param name="start">起始位置</param>
        /// <param name="limit">最大条数</param>
        /// <param name="sort">排序列</param>
        /// <param name="dir">排序方向("DESC","ASC")</param>
        /// <param name="count">取得记录数</param>
        /// <returns>TList<???></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public  TList<TbTeaPublicSourceDict>  GetByPage(string whereClause, int start, int limit, string sort, string dir, out int count)
        {
            string sOrder = "";
            if (! String.IsNullOrEmpty(sort ) && sort.ToUpper() != "ID")
            {
                sOrder = sort.Insert(1, "_") + " " + dir;
            }
            else
            {
                 if (sort != null && sort.ToLower() == "id") sOrder = sort + " " + dir;
            }
			
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.GetPaged(whereClause, sOrder, (int)start / limit, limit, out count);
        }
		
		
		
        /// <summary>
        /// 分页查询计数
        /// </summary>
        /// <param name="whereClause">查询调价</param>
		/// <param name="startRowIndex">起始值</param>
        /// <param name="maximumRows">每页的最大值</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, false)]
        public int GetCount(string whereClause, int startRowIndex, int maximumRows)
        {
            if (TotalCount != -1)
            {
                return TotalCount;
            }
            else
            {
                DataRepository.Provider.TbTeaPublicSourceDictProvider.GetTotalItems(whereClause, out TotalCount);
                return TotalCount;
            }
        }
		
		
		
		
		/// <summary>
        /// 更新对象，传入的是一个对象
        /// </summary>
        /// <param name="item">需要更新的对象</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, true)]
        public bool Update(TbTeaPublicSourceDict item)
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Update(item);
        }
		
		/// <summary>
        /// 更新对象，传入的是一个Tlist对象
        /// </summary>
        /// <param name="items">需要更新的TList对象</param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, false)]
        public int Update(TList<TbTeaPublicSourceDict> items)
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Update(items);
        }
		
		
		
		/// <summary>
        /// 更新对象，传入的是此对象的多个属性，属性个数为  7
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Update, false)]
        public bool Update(
		System.String SDicName, System.Int32? IParentId, 
			System.Int32? ILevel, System.Int32? IOwnerUserId, System.Int32? IPublic, 
			System.Int32? ICourseId, System.Int32? ITeaSourceDictId, System.Int32 Id
		)
        {
			
			TbTeaPublicSourceDict item =new TbTeaPublicSourceDict();
			
			
			

			item.SDicName = SDicName;
			item.IParentId = IParentId;
			item.ILevel = ILevel;
			item.IOwnerUserId = IOwnerUserId;
			item.IPublic = IPublic;
			item.ICourseId = ICourseId;
			item.ITeaSourceDictId = ITeaSourceDictId;
			
			
			item.Id = Id;
			
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Update(item);
        }
		
		
		/// <summary>
        /// 通过ID来删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public int Del(string ids)
        {
		
			TList<TbTeaPublicSourceDict> tmpList= GetByPage("id in ("+ids+")",0,int.MaxValue);
			

            return Del(tmpList);

        }
		
		
		/// <summary>
        /// 通过ID来删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public bool Del(int id)
        {

            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Delete(id);

        }
		
		/// <summary>
        /// 通过对象删除记录
        /// </summary>
        /// <param name="item">对象</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, false)]
        public bool Del(TbTeaPublicSourceDict item)
        {

            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Delete(item);

        }
		
		/// <summary>
        /// 通过对象删除记录
        /// </summary>
        /// <param name="items">需删除的TList对象</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, false)]
        public int Del(TList<TbTeaPublicSourceDict> items)
        {

            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Delete(items);

        }
		
		
		/// <summary>
        /// 插入一个对象
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
		 [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public bool Insert(TbTeaPublicSourceDict item)
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Insert(item);
        }
		
		/// <summary>
        /// 插入一个TList对象
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
		 [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Insert, false)]
        public int Insert(TList<TbTeaPublicSourceDict> items)
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Insert(items);
        }
        
		/// <summary>
        /// 更具条件查找
        /// </summary>
        /// <param name="whereClause">需要查找的条件</param>
        /// <returns>TList对象</returns>
        public TList<TbTeaPublicSourceDict> GetByCondition(string whereClause)
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Find(whereClause);
        }
		
		


//	CREATE Function [dbo].[fn_TeaPublicSourceDictGetChildren]

//	(@root as int) returns @Subs TABLE

//	( ID int  not null,

//			lvl int not null,

//	unique	clustered(lvl,id)   ---用于筛选级别的索引

//	)AS

//	BEGIN

//		declare @lvl as int;

//	set @lvl=0;

//	Insert into @Subs(id,lvl) select id,@lvl from dbo.tb_TeaPublicSourceDict where id=@root; --插入根结点

//	while @@rowcount >0   --当存在上级员工

//	begin

//		set @lvl=@lvl+1;  --递增级别计数器

//		insert into @subs(id,lvl)

//			select c.id,@lvl

//			from @Subs as p			--p=父级

//		join dbo.tb_TeaPublicSourceDict as c			--c=子级

//		on p.lvl=@lvl -1      --从上一级筛选父亲

//			and c.I_ParentID=p.id;

//	end

//	RETURN;

//	END



		
		
		/// <summary>
        /// 通过ID来删除对象，加强版，包括其子树,注意：需要使用对应的函数fn_XXXGetChildren
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns></returns>
        [System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Delete, true)]
        public int DelTree(int id)
        {
			
			TList< TbTeaPublicSourceDict > items = GetByPage("ID in (select id from [fn_TeaPublicSourceDictGetChildren](" + id.ToString() + ") ",0,int.MaxValue);

            return DataRepository.Provider.TbTeaPublicSourceDictProvider.Delete(items);

        }


#endregion 表生成代码

#region 兼容代码



		 /// <summary>
        ///兼容查询
        /// </summary>
        /// <param name="whereClause">查询条件</param>
        /// <param name="start">起始位置</param>
        /// <param name="limit">最大条数</param>
        /// <param name="sort">排序列</param>
        /// <param name="dir">排序方向("DESC","ASC")</param>
        /// <param name="count">取得记录数</param>
        /// <returns>TList<???></returns>
		
        public  TList<TbTeaPublicSourceDict>  getByPageDataBase( int start, int limit, string sort,string whereClause, out int count)
        {
		///(0, 10000, "I_Level ASC,I_Group ASC,ID ASC", "I_Type=1 and id<>1", out count);
            string sOrder = "";
            string[] sortTmps=sort.Split(' ');

            if (!String.IsNullOrEmpty(sort) && sortTmps[0].ToUpper() != "ID")
            {

                sOrder = sort.Insert(1, "_") ;
            }
            else
            {
                 if (sort != null && sort.ToLower() == "id") sOrder = sort + " " ;
            }
			
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.GetPaged(whereClause, sOrder, start , limit, out count);
        }


 /// 取所有的对象,例如TList<???>
        /// </summary>
        /// <returns></returns>
		[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select, true)]
        public  TList<TbTeaPublicSourceDict> findAll()
        {
            return DataRepository.Provider.TbTeaPublicSourceDictProvider.GetAll();
        }
		

		 public  TList<TbTeaPublicSourceDict> findByProperty(String propertyName, Object value)
        {
            TList<TbTeaPublicSourceDict> tmpList = new TList<TbTeaPublicSourceDict>();
            try
            {

                string whereC = "";
				 string FirC=propertyName.Substring(0,1);
                if (FirC != "I" || FirC != "F")
                {
                
                    value="'"+value.ToString()+"'";
                }
				
                if (!String.IsNullOrEmpty(propertyName) && propertyName.ToUpper() != "ID")
                {
                    whereC = propertyName.Insert(1, "_") + "= " + value.ToString();
                }
                else
                {
                    whereC = propertyName + "= " + value.ToString();
                }

              
                tmpList = GetByPage(whereC,0,int.MaxValue);
                return tmpList;
            }
            catch (Exception re)
            {
                throw re;
            }
        }//end for findByProperty
		
		
		
		  /*
       *get the Object through SDicName
       */
	public IList<TbTeaPublicSourceDict> findBySDicName(Object _SDicName)
        {
            return findByProperty("SDicName",_SDicName);
         }
		
		
		  /*
       *get the Object through IParentId
       */
	public IList<TbTeaPublicSourceDict> findByIParentId(Object _IParentId)
        {
            return findByProperty("IParentId",_IParentId);
         }
		
		
		  /*
       *get the Object through ILevel
       */
	public IList<TbTeaPublicSourceDict> findByILevel(Object _ILevel)
        {
            return findByProperty("ILevel",_ILevel);
         }
		
		
		  /*
       *get the Object through IOwnerUserId
       */
	public IList<TbTeaPublicSourceDict> findByIOwnerUserId(Object _IOwnerUserId)
        {
            return findByProperty("IOwnerUserId",_IOwnerUserId);
         }
		
		
		  /*
       *get the Object through IPublic
       */
	public IList<TbTeaPublicSourceDict> findByIPublic(Object _IPublic)
        {
            return findByProperty("IPublic",_IPublic);
         }
		
		
		  /*
       *get the Object through ICourseId
       */
	public IList<TbTeaPublicSourceDict> findByICourseId(Object _ICourseId)
        {
            return findByProperty("ICourseId",_ICourseId);
         }
		
		
		  /*
       *get the Object through ITeaSourceDictId
       */
	public IList<TbTeaPublicSourceDict> findByITeaSourceDictId(Object _ITeaSourceDictId)
        {
            return findByProperty("ITeaSourceDictId",_ITeaSourceDictId);
         }
		
		
#endregion 兼容代码
#region 自定义代码


		
#endregion 自定义代码

	}
}